From 30cc28333dd3ce5f62409e6a14ae2641c512f032 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 29 May 2014 18:11:27 -0700 Subject: [PATCH] Improve errors slightly --- src/cargo/sources/git.rs | 4 ++-- src/cargo/util/result.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cargo/sources/git.rs b/src/cargo/sources/git.rs index 740b934d1..f2bc69fdc 100644 --- a/src/cargo/sources/git.rs +++ b/src/cargo/sources/git.rs @@ -317,12 +317,12 @@ fn git(path: &Path, verbose: bool, str: &str) -> ProcessBuilder { fn git_inherit(path: &Path, verbose: bool, str: String) -> CargoResult<()> { git(path, verbose, str.as_slice()).exec().map_err(|err| - human_error(format!("Couldn't execute `git {}`: {}", str, err), None::<&str>, err)) + human_error(format!("Executing `git {}` failed: {}", str, err), None::<&str>, err)) } fn git_output(path: &Path, verbose: bool, str: String) -> CargoResult { let output = try!(git(path, verbose, str.as_slice()).exec_with_output().map_err(|err| - human_error(format!("Couldn't execute `git {}`", str), None::<&str>, err))); + human_error(format!("Executing `git {}` failed", str), None::<&str>, err))); Ok(to_str(output.output.as_slice()).as_slice().trim_right().to_str()) } diff --git a/src/cargo/util/result.rs b/src/cargo/util/result.rs index 8ce1b72fe..26b235b88 100644 --- a/src/cargo/util/result.rs +++ b/src/cargo/util/result.rs @@ -69,7 +69,7 @@ pub fn toml_error(desc: &'static str, error: toml::Error) -> CargoError { } } -#[deriving(Show,Clone)] +#[deriving(Eq,Clone)] pub struct CargoError { pub kind: CargoErrorKind, desc: CargoErrorDescription, @@ -77,7 +77,16 @@ pub struct CargoError { cause: Option> } -#[deriving(Show,Clone)] +impl Show for CargoError { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self.desc { + StaticDescription(string) => write!(f, "{}", string), + BoxedDescription(ref string) => write!(f, "{}", string) + } + } +} + +#[deriving(Eq,Show,Clone)] enum CargoErrorDescription { StaticDescription(&'static str), BoxedDescription(String) @@ -118,6 +127,7 @@ impl CargoError { } } +#[deriving(Eq)] pub enum CargoErrorKind { HumanReadableError, InternalError, -- 2.30.2